import { Dispatch } from "redux"
import {
    getFindMainRequest,
    getCitiesRequest,
    getLocalRequest,
} from '@/api/request'
import * as actionTypes from '../constants'

export const getHomeDataAction=()=>{
    return(dispatch:Dispatch)=>{
        return Promise.all([
            getFindMainRequest()
        ]).then(([FindMainImgResult])=>{
            // console.log(FindMainImgResult.data)
            dispatch(setFindMainTab(FindMainImgResult.data))
            // dispatch(setFindMainImg(FindMainTabResult.data))
        })
    }
}

export const getCitiesDataAction=()=>{
    return(dispatch:Dispatch)=>{
        return Promise.all([
            getCitiesRequest()
        ]).then(([FindCitiesResult])=>{
            // console.log(FindCitiesResult.data)
            dispatch(setFindCities(FindCitiesResult.data))
        })
    }
}

export const getLocalDataAction=()=>{
    return(dispatch:Dispatch)=>{
        getLocalRequest().then(data=>{
            dispatch(setFindLocal(data.data))
        })
    }
}

export const setFindMainTab=(data:any[])=>({
    type:actionTypes.SET_MAIN_TAB,
    data
})
export const setFindMainImg=(data:any[])=>({
    type:actionTypes.SET_MAIN_IMG,
    data
})

export const setFindCities=(data:any[])=>({
    type:actionTypes.SET_CITIES,
    data
})

export const setFindLocal=(data:any[])=>({
    type:actionTypes.SET_LOCAL,
    data
})
